<?php

namespace Api\Controller;

use Think\Controller;

//加载commons下的functions.php自定义函数库
load("@.functions");

/**
 * Description of EquipmentApiController
 *
 * @author Shangyidong
 */
class FishplaceApiController extends Controller {
    /*
     * 附近钓场表名：dy_fishery_nearby
     */

    function get_fishplace() {
        header("Content-Type: text/html; charset=utf-8");
        $id = $_GET['id'];
        if ($id == '' || !is_numeric($id) || $id <= 0) {
            $result['code'] = "1060101";
            //$result['reason'] = "请输入正确的钓场id";
            echo json_encode($result, JSON_PRETTY_PRINT);
            die();
        }
        $Fishplace = M("fishery_nearby"); // 实例化Fishplace对象
        $fishplace = $Fishplace->where("id=".$id)->find();
//                echo $Fishplace->getLastSql();
        $result['code'] = "200";
        $result['result'] = $fishplace;
        echo json_encode($result, JSON_PRETTY_PRINT);
    }
    
    function list_fishplace(){
        header("Content-Type: text/html; charset=utf-8");
        $fishplace= D("fishery_nearby");
        $total = $fishplace->count();
        $pageSize = $_GET['pageSize'];
        if ($pageSize == '' || !is_numeric($pageSize) || $pageSize <= 0) {
            $pageSize = 10;
        }
        $page = $_GET['page'];
        $page = new \Component\Page($total, $pageSize);
        $sql = "select * from dy_fishery_nearby " . $page->limit;
        $info = $fishplace->query($sql);
//        $pageList = $page->fpage();//页码列表
//        show_bug($info);
//        $this->assign("info", $info);//将变量传递到模板
        $result['code'] = "200";
        $result['result'] = $info;
        echo json_encode($result, JSON_PRETTY_PRINT);
    }

}
